﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebSearcher
{
    public partial class Feedback : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string subject = this.txtSubject.Text.Trim();
            string type = this.ddlType.SelectedValue;
            string content = this.txtContent.Text.Trim();
            string name = this.txtName.Text.Trim();
            string email = this.txtEmail.Text.Trim();
            string qq = this.txtQQ.Text.Trim();
            string ip = Request.UserHostAddress;

            string strConn = ConfigurationManager.ConnectionStrings["connectionString"].ToString();

            string strInsert = "INSERT INTO [FtpSearchEngine].[dbo].[t_feedback]" +
                "([subject],[type],[content],[name],[email],[qq],[ip],[add_time])VALUES" +
                "(@Subject,@Type,@Content,@Name,@Email,@Qq,@Ip,@AddTime)";
            SqlParameter[] sqlParams = {
                                            new SqlParameter("@Subject", SqlDbType.Char, 100),
                                            new SqlParameter("@Type", SqlDbType.Char, 10), 
                                            new SqlParameter("@Content", SqlDbType.VarChar), 
                                            new SqlParameter("@Name", SqlDbType.Char, 20), 
                                            new SqlParameter("@Email", SqlDbType.Char, 100), 
                                            new SqlParameter("@Qq", SqlDbType.Char, 20), 
                                            new SqlParameter("@Ip", SqlDbType.Char, 20), 
                                            new SqlParameter("@AddTime", SqlDbType.DateTime)

            };
            sqlParams[0].Value = subject;
            sqlParams[1].Value = type;
            sqlParams[2].Value = content;
            sqlParams[3].Value = name;
            sqlParams[4].Value = email;
            sqlParams[5].Value = qq;
            sqlParams[6].Value = ip;
            sqlParams[7].Value = DateTime.Now;

            using (SqlConnection conn = new SqlConnection(strConn))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(strInsert, conn))
                {
                    cmd.Parameters.AddRange(sqlParams);
                    cmd.ExecuteNonQuery();

                    Response.Redirect("Feedback_Success.aspx");
                }
            }
        }
    }
}
